home *** CD-ROM | disk | FTP | other *** search
/ PC Pro 2005 December / DPPCPRO1205.ISO / Essentials / Programming / Basic4GL / Setup Basic4GL v2.3.1.exe / $INSTDIR / Programs / Boom02.gb < prev    next >
Encoding:
Text File  |  2005-07-29  |  3.5 KB  |  193 lines

  1. ' Boom02
  2. ' Written by Scott Brosious
  3.  
  4. const width = 200, height = 200
  5. const nops = 1000         ' Number of pixels
  6. const nos = 250
  7. const Speed = 1           ' Speed   
  8.  
  9. const scale1 = 8 
  10. const scale2 = 4
  11.  
  12. dim count
  13.  
  14. count = nops + nos
  15.  
  16. dim xcntr,ycntr
  17.  
  18. xcntr = width / 2    
  19. ycntr = height / 2   
  20.  
  21. dim buffer1(width)(height)
  22. dim buffer2(width)(height)
  23.  
  24. dim col1#,col2#,col3#,col4#
  25.  
  26. dim texture
  27. dim a   
  28. dim i,j 
  29. dim time  ' Current time
  30. dim t1,t2 ' Starting and ending time variables
  31.  
  32. dim xpos(count) ' Xposition
  33. dim ypos(count) ' Yposition
  34. dim ang(count)  ' Angles
  35. dim st(count)   ' Start time
  36. dim et(count)   ' End time
  37. dim mt(count)   ' Time to move
  38.  
  39. for i = 1 to count
  40.  
  41. gosub Inittime
  42.  
  43. st(i) = t1
  44. et(i) = t2
  45.  
  46. gosub Angles
  47.  
  48. ang(i) = a
  49.  
  50. next
  51.  
  52. ' Set 2D mode
  53. glMatrixMode (GL_PROJECTION)
  54. glLoadIdentity ()
  55. glOrtho (0, width, 0, height, -1, 1)
  56. glMatrixMode (GL_MODELVIEW)
  57. glDisable (GL_DEPTH_TEST)
  58.  
  59. texture = LoadTexture ("data\fb01.png")
  60.  
  61. glEnable (GL_TEXTURE_2D)    
  62.  
  63. ' Translucency, Blending
  64. glBlendFunc(GL_SRC_ALPHA,GL_ONE)
  65. glEnable(GL_BLEND)
  66.  
  67. while true    
  68.  
  69. ' Clear screen   
  70. glClear (GL_COLOR_BUFFER_BIT)   
  71.  
  72. glBindTexture (GL_TEXTURE_2D, texture)
  73.  
  74. for i = 1 to count       
  75.  
  76. if i > nops then et(i) = width endif
  77.  
  78. if time > st(i) then mt(i) = mt(i) + 1 :endif ' If current time greater then start time then move it.
  79.  
  80. if mt(i) > et(i) then gosub Refresh :endif ' If movetime greater then endtime start again
  81.  
  82. xpos(i)= xcntr + cosd(ang(i)) * (mt(i) * Speed)
  83. ypos(i)= ycntr + sind(ang(i)) * (mt(i) * Speed)
  84.  
  85. if xpos(i) < 0 or xpos(i) > width then goto skip1 endif
  86. if ypos(i) < 0 or ypos(i) > height then goto skip1 endif
  87.  
  88. if i < nops - 1 then buffer1(xpos(i))(ypos(i)) = buffer1(xpos(i))(ypos(i)) + 1 endif
  89.  
  90. if i > nops then buffer2(xpos(i))(ypos(i)) = 10 endif
  91.  
  92. skip1:       
  93.  
  94. next 
  95.  
  96. for j = 0 to height
  97. for i = 0 to width
  98.  
  99. buffer2(i)(j) = buffer2(i)(j) - 1
  100.  
  101. next
  102. next
  103.  
  104. glBegin (GL_QUADS)
  105.  
  106. for j = 0 to height
  107. for i = 0 to width
  108.  
  109. col1# = buffer1(i)(j)
  110.  
  111. if col1# = 0 then goto skip2 endif
  112. if col1# > 100 then col1# = 100 endif
  113.  
  114. col2# =  col1# / 100
  115.  
  116.       glColor4f (1, 1, 1, col2#)
  117.  
  118.       glTexCoord2f (0, 1)                         
  119.       glVertex2f (i - scale1,j + scale1)     ' Top left
  120.  
  121.       glTexCoord2f (0, 0)                         
  122.       glVertex2f (i - scale1,j - scale1)     ' Bottom left
  123.             
  124.       glTexCoord2f (1, 0)                         
  125.       glVertex2f (i + scale1,j - scale1)     ' Bottom right    
  126.  
  127.       glTexCoord2f (1, 1)                         
  128.       glVertex2f (i + scale1,j + scale1)     ' Top right
  129.  
  130. skip2:
  131.  
  132. col3# = buffer2(i)(j)
  133.  
  134. if col3# < 0 then goto skip3 endif
  135.  
  136.       col4# = col3# / 10
  137.       
  138.       glColor4f (1, 1, 1, col4#)
  139.  
  140.       glTexCoord2f (0, 1)                         
  141.       glVertex2f (i - scale2,j + scale2)     ' Top left
  142.  
  143.       glTexCoord2f (0, 0)                         
  144.       glVertex2f (i - scale2,j - scale2)     ' Bottom left
  145.             
  146.       glTexCoord2f (1, 0)                         
  147.       glVertex2f (i + scale2,j - scale2)     ' Bottom right    
  148.  
  149.       glTexCoord2f (1, 1)                         
  150.       glVertex2f (i + scale2,j + scale2)     ' Top right
  151.  
  152. skip3:       
  153.  
  154. next
  155. next
  156.  
  157. glEnd ()
  158.  
  159. ' Display output
  160. SwapBuffers ()
  161.  
  162. time = time + 1
  163.  
  164. wend
  165.  
  166. ReFresh:
  167.  
  168. gosub InitTime  
  169. st(i) = t1
  170. et(i) = t2
  171. mt(i) = 0
  172. gosub Angles
  173. ang(i) = a
  174.  
  175. return
  176.  
  177. InitTime:
  178.  
  179. t1 = rnd() % 75 
  180. t2 = rnd() % width
  181.  
  182. return              
  183.  
  184. Angles:
  185.  
  186. a = rnd() % 360
  187.  
  188. return
  189.  
  190.  
  191.  
  192.  
  193.